export default {
	data() {
		return {
			stationPriceList: [], // 价格列表
			displayPriceList: [], // 用于显示的价格列表（当前和下一个时段）
			allPriceList: [], // 用于显示全部时段的价格列表
		}
	},

	methods: {
		// 格式化时间
		formatTime(hour, minute) {
			return `${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`
		},

		// 格式化时间段显示
		formatTimeRange(startTime, endTime) {
			return `${this.formatTime(...startTime)}-${this.formatTime(...endTime)}`
		},

		// 处理价格数据
		processPriceData(priceData) {
			const {
				startTime,
				endTime,
				...rest
			} = priceData
			return {
				...rest,
				displayTime: this.formatTimeRange(startTime, endTime),
				timeRange: {
					start: startTime[0] * 60 + startTime[1],
					end: endTime[0] * 60 + endTime[1]
				}
			}
		},

		// 获取当前时间分钟数
		getCurrentMinutes() {
			const now = new Date()
			return now.getHours() * 60 + now.getMinutes()
		},

		// 获取当前时间段
		getCurrentTimeSegment() {
			if (!this.stationPriceList.length) return null
			const currentMinutes = this.getCurrentMinutes()

			return this.stationPriceList.find(segment => {
				const processedData = this.processPriceData(segment)
				return currentMinutes >= processedData.timeRange.start &&
					currentMinutes <= processedData.timeRange.end
			})
		},

		// 获取下一个时间段
		getNextTimeSegment() {
			if (!this.stationPriceList.length) return null
			const currentMinutes = this.getCurrentMinutes()

			return this.stationPriceList.find(segment => {
				const processedData = this.processPriceData(segment)
				return processedData.timeRange.start > currentMinutes
			})
		}
	},

	computed: {
		// 获取当前时间段的索引
		currentTimeSegmentIndex() {
			if (!this.allPriceList.length) return -1
			const currentMinutes = this.getCurrentMinutes()

			return this.allPriceList.findIndex(segment => {
				const processedData = this.processPriceData(segment)
				return currentMinutes >= processedData.timeRange.start &&
					currentMinutes <= processedData.timeRange.end
			})
		}
	}
}